<?php
	define("LOG_TBL", "log");
	
	function writeError($message){
		
		if (@getenv("HTTP_X_FORWARDED_FOR")){ 
			$u_ip = @getenv("HTTP_X_FORWARDED_FOR"); 
		} else { 
			$u_ip = @getenv("REMOTE_ADDR"); 
		}
		
		$u_timestamp = time();
		$u_host = @gethostbyaddr($u_ip);
		$u_referrer = @getenv("HTTP_REFERER");
		
		$sql = "INSERT INTO " . LOG_TBL . " (ip,host,referrer,timestamp,level,message) " . 
			"VALUES (\"$u_ip\",\"$u_host\",\"$u_referrer\",\"$u_timestamp\",'ERROR','" . $message . "')";
		
		mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());	
	}
	
?>
